<?php
/* Author: tbloc@cantho.gov.vn */
class Chi_thue{  
//Properties
private $CHI_ID;
private $TT_ID;
private $SO_TIEN;
//properties set get 
public function setCHI_ID($CHI_ID) 
{
	$this->CHI_ID = $CHI_ID;
}
public function getCHI_ID()
{
	return $this->CHI_ID;
}	        
public function setTT_ID($TT_ID) 
{
	$this->TT_ID = $TT_ID;
}
public function getTT_ID()
{
	return $this->TT_ID;
}	        
public function setSO_TIEN($SO_TIEN) 
{
	$this->SO_TIEN = $SO_TIEN;
}
public function getSO_TIEN()
{
	return $this->SO_TIEN;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `chi_thue`(                        
			`CHI_ID`, 
				`TT_ID`, 
				`SO_TIEN` 
		)
	VALUES(
    		:CHI_ID, 
	    		:TT_ID, 
	    		:SO_TIEN 
	    );";
	$parameters = array(
			":CHI_ID", 
				":TT_ID", 
				":SO_TIEN" 
		);
    $values = array(  
    		$this->getCHI_ID(), 
	    		$this->getTT_ID(), 
	    		$this->getSO_TIEN() 
	    );
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR //Kiem tra lai kieu du lieu nhe
    );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
	$this->setTT_ID($lastInsertID);
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "delete from `chi_thue`
	                where `TT_ID` = :TT_ID and `CHI_ID`=:CHI_ID;";
	        $parameters = array(":TT_ID",":CHI_ID");
	        $values = array($this->getTT_ID(),$this->getCHI_ID());
	        $types = array(PDO::PARAM_INT,PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `chi_thue` SET 
			`CHI_ID`=:CHI_ID,
				`TT_ID`=:TT_ID,
				`SO_TIEN`=:SO_TIEN,
			WHERE `TT_ID` = :TT_ID;";
	            $parameters = array(
			":CHI_ID",
				":TT_ID",
				":SO_TIEN",
			);
	// Kiem tra dau , nhe
	$values = array(  
			$this->getCHI_ID(),
				$this->getTT_ID(),
				$this->getSO_TIEN(),
		);
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($db = null) {
	if ($db != null) {
	$sql = "SELECT
			`CHI_ID`,
				`TT_ID`,
				`SO_TIEN`
			FROM `chi_thue` WHERE `TT_ID` = :TT_ID ";
	$parameters = array(":TT_ID");
	$values = array($this->getTT_ID());
	$types = array(PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
		$this->setCHI_ID($row->CHI_ID);
		$this->setTT_ID($row->TT_ID);
		$this->setSO_TIEN($row->SO_TIEN);
	}
	return $this;
		}
	}
	
        public function getByID_CHI($db = null) {
	if ($db != null) {
	$sql = "SELECT
			`CHI_ID`,
				`TT_ID`,
				`SO_TIEN`
			FROM `chi_thue` WHERE `CHI_ID` = :CHI_ID ";
	$parameters = array(":CHI_ID");
	$values = array($this->getCHI_ID());
	$types = array(PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
		$this->setCHI_ID($row->CHI_ID);
		$this->setTT_ID($row->TT_ID);
		$this->setSO_TIEN($row->SO_TIEN);
	}
	return $this;
		}
	}
        
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`CHI_ID`,
				`TT_ID`,
				`SO_TIEN`,
			FROM `chi_thue` ";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new chi_thue();
    	 $obj->setCHI_ID($row->CHI_ID);
		 $obj->setTT_ID($row->TT_ID);
		 $obj->setSO_TIEN($row->SO_TIEN);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

